package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.bean.response.QueryPageResourceRes;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/12/20 10:33
 * description:
 */
public class AppHomeThemeRvAdapter extends RecyclerView.Adapter<AppHomeThemeRvAdapter.AppHomeThemeRvHolder> {
    private Context mContext;
    private List<QueryPageResourceRes.ResourceListBean> viewData;


    private BaseInterface baseInterface;

    public interface BaseInterface {
        public void onClick(View view, String url, String syslabl,int need_header,int modularId);
    }

    public void setBaseInterface(BaseInterface baseInterface) {
        this.baseInterface = baseInterface;
    }


    public AppHomeThemeRvAdapter(Context context) {
        mContext = context;
    }

    @Override
    public AppHomeThemeRvHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.apphome_theme_item, parent, false);

        return new AppHomeThemeRvHolder(view);
    }

    @Override
    public void onBindViewHolder(AppHomeThemeRvHolder holder, final int position) {
        Glide.with(mContext)
                .load(viewData.get(position).getResource_url())
                .into(holder.itemIV);

        holder.itemIV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (viewData!=null){
                    QueryPageResourceRes.ResourceListBean listBean = viewData.get(position);
                    String link_url = listBean.getLink_url();
                    int need_header = listBean.getNeed_header();
                    String sys_label = listBean.getSys_label();
                    int modularId = listBean.getModularId();
                    if (baseInterface!=null){
                        baseInterface.onClick(v,link_url,sys_label,need_header, modularId);
                    }
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return null == viewData ? 0 : viewData.size();
    }

    public void setViewData(List<QueryPageResourceRes.ResourceListBean> viewData) {
        this.viewData = viewData;
    }

    public static class AppHomeThemeRvHolder extends RecyclerView.ViewHolder {

        private final ImageView itemIV;

        public AppHomeThemeRvHolder(View itemView) {
            super(itemView);
            itemIV = (ImageView) itemView.findViewById(R.id.apphome_theme_iv);
        }
    }

}
